package com.cyf.db.mapper;

import com.cyf.db.bean.Parking;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ParkingMapper {

	@Select("select * from parking where id = #{id}")
	Parking getParkingById(@Param("id") Integer id);

	// 根据第三方id查询车场列表
	@Select("select p.* from parking p , thirdparkingmap t where p.id = t.parkingId and thirdId = #{thirdId}")
	List<Parking> getByThirdId(@Param("thirdId") int thirdId);

	// 查询支持车位预约的车场 经纬度相差1度 （1度=111公里）
	@Select("select * from parking where " +
			"latitude > #{latitude}-1 and latitude < #{latitude}+1 " +
			"and longitude > #{longitude}-1 and longitude < #{longitude}+1")
	List<Parking> getParkingsByUseBookingWithRange(@Param("useBooking") Integer useBooking, @Param("longitude") double longitude, @Param("latitude") double latitude);


	//查找剩余车位数
	@Select("select carport from parking where id = #{parkingId};")
	Integer getParkingSpace(@Param("parkingId") int parkingId);

	//更新车场剩余车位数
	@Update("update parking set carport = #{space} where id = #{parkingId};")
	void updateParkingSpace(@Param("parkingId") int parkingId,@Param("space") int space);

	//获取车场总车位数
	@Select("select allCarport from parking where id = #{parkingId}")
	Integer getParkingAllCarport(@Param("parkingId") int parkingId);
}
